package com.banciyuan.bcywebview.biz.circles.smooth.decoration;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;

import com.banciyuan.bcywebview.biz.main.mainpage.timeline.TimelineCardType;

/**
 * Created by squall on 2016/6/28.
 */
public class PinterestItemOffsetDecoration extends RecyclerView.ItemDecoration {
    private int offset;

    public PinterestItemOffsetDecoration(int offset) {
        this.offset = offset;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view,
                               RecyclerView parent, RecyclerView.State state) {
        int position = parent.getChildAdapterPosition(view);
        int type = parent.getAdapter().getItemViewType(position);
        if (type == TimelineCardType.SMALL_CARD || type == TimelineCardType.SMALL_CARD_GROUP || type == TimelineCardType.SMALL_MAIN_CARD
                || type == TimelineCardType.SMALL_DAILY_CARD || type == TimelineCardType.SMALL_WRITE_CARD || type == TimelineCardType.SMALL_GROUPPOST_CARD
                || type == TimelineCardType.SMALL_LONGDAILY_CARD || type == TimelineCardType.SMALL_VIDEO_CARD) {
            StaggeredGridLayoutManager.LayoutParams slp = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
            if (slp.getSpanIndex() == 0) {
                outRect.right = offset;
            } else if (slp.getSpanIndex() == 1) {
                outRect.left = offset;
            }
            outRect.bottom = offset * 2;
        }
    }
}